class Solution8 {
    public int[][] heightQueue(int[][] people) {
    int n = people.length;
    int[][] result = new int[n][2];
    Arrays.sort(people, (a, b) -> {return b[0] != a[0] ? b[0] - a[0] : a[1] - b[1];});
    List<int[]> list = new LinkedList<int[]>();
    list.add(people[0]);
    for(int i = 1; i < n; i++) {
        list.add(people[i][1], people[i]);
    }
    int i = 0;
    for(int[] l : list) {
        result[i++] = l;
    }
    return result;
    }
}